from .exts import db
from datetime import datetime


class BaseModel(db.Model):  # 基类模型
    __abstract__ = True
    id = db.Column(db.Integer, primary_key=True, comment='id主键')
    add_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
    upd_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')

    def yes(self):
        try:
            db.session.add(self)
            db.session.commit()
            return True
        except Exception as e:
            print('>>add it error', e)
            return False

